package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sg.hms.Model.Role;
import com.sg.hms.Service.FoodService;
import com.sg.hms.ServiceImpl.FoodServiceImpl;
/**
 * 
 * @author 张杨
 *
 */

public class AddFoodController extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter pw=resp.getWriter();
		HttpSession session=req.getSession();
		FoodService fService=new FoodServiceImpl();
		String fname=req.getParameter("fname");
		Role role= (Role) session.getAttribute("currentrole");
		int elId=role.getRoleId();
		String fweight=req.getParameter("fweight");
		int weight= Integer.parseInt(fweight);
		//if(weight>0){			
			int a=fService.addFood(elId, fname,weight);
			req.getRequestDispatcher("foodManage").forward(req, resp);
			//pw.write('1');
		//}else {
			//pw.write('0');
		//}
	}
	
}
